package com.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import com.base.standardization;
import com.data.Data;
import com.db.sevent.WorkUserEvent;

import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.JToolBar;

public class P3 extends JPanel implements standardization {
	public JLabel imgBox;
	//图片显示区域的宽
	private int imgBoxWidth=488,imgBoxHeigth=431;
	JButton bt08;
	JButton bt09;
	JButton bt10;
	JScrollPane jsPane;
	
	public static P3 instance = new P3();
	private P3() {
		init();
		initEvent();
		event();
	}
	public void init() {
		int WIDTH = Data.config.PanelW3;
		int HEIGHT = Data.config.HEIGHT;
		setBounds(Data.config.PanelW1 + Data.config.PanelW2, 0, WIDTH, HEIGHT);
		setBackground(Color.CYAN);
		setLayout(null);

		bt08 = new JButton();
		bt09 = new JButton();
		bt10 = new JButton();
		imgBox = new JLabel();
		jsPane = new JScrollPane(imgBox);
		initLayout();
		initOther();
		add(bt08);
		add(bt09);
		add(bt10);
		jsPane.setBounds(10, 10, 494, 461);
		jsPane.getVerticalScrollBar().setUnitIncrement(30);
		add(jsPane);
	}

	@Override
	public void initLayout() {
		imgBox.setBounds(20, 20, imgBoxWidth, imgBoxHeigth);
		bt08.setBounds(20, 481, 109, 49);
		bt09.setBounds(213, 481, 109, 49);
		bt10.setBounds(395, 481, 109, 49);
		
	}

	@Override
	public void initOther() {
		// TODO Auto-generated method stub
		bt08.setText(Data.config.bt08Title);
		bt09.setText(Data.config.bt09Title);
		bt10.setText(Data.config.bt10Title);
//		jsPane
	}

	@Override
	public void initEvent() {
		// TODO Auto-generated method stub
//		src/other/img/按钮开启.png
//		String url = "src/other/img/按钮开启.png";
//		url = "https://i0.hdslb.com/bfs/archive/16ad7f08e2ae159b1d8fbf0abb71decb85535b0d.jpg";
//		setImgBoxData(url);
	}

	@Override
	public void event() {
		// TODO Auto-generated method stub
		
		bt08.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
//				System.out.println("bt08");
				new WorkUserEvent().auditUserWork("True");
			}
		});
		bt09.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new WorkUserEvent().auditUserWork("False");
			}
		});
		bt10.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new WorkUserEvent().auditUserWork("Skip");
			}
		});
	}

	public void setImgBoxData(String url) {
		ImageIcon image = null;
		try {
			if(url.indexOf("http")==-1) {
        		image = new ImageIcon(url);
        	}else {
        		image = new ImageIcon(new URL(url));
        	}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		Image img=null;
		try {
			long iconWidth = image.getIconWidth();
			long iconHeight = image.getIconHeight();
			if(iconWidth<0){
				return;
			}
			long height = (iconWidth*imgBoxHeigth)/imgBoxWidth;//iconHeight / (iconWidth / imgBoxWidth);
			img = image.getImage();
			img = img.getScaledInstance(488, (int)height, Image.SCALE_AREA_AVERAGING);
		} catch (Exception e) {
			System.out.println("调节大小失败");
			img = image.getImage();
		}
		image.setImage(img);
		imgBox.setIcon(image);
	}
	
	public static void main(String[] args) {
		util.GUIUtil.showPanel(P3.instance);
	}
}
